package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.FodderRecord;
import com.ayou.eggguard.farm.service.FodderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fodder")
public class FodderController {
    @Autowired
    private FodderService fodderService;

    @GetMapping("/getPurchaseRecord")
    public Result<PageBean<FodderRecord>> getPurchaseRecord(Integer pageNum,
                                                            Integer pageSize,
                                                            @RequestParam(required = false) String number){
        PageBean<FodderRecord> pb=fodderService.getPurchaseRecord(pageNum,pageSize,number);
        return Result.success(pb);
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        fodderService.delete(id);
        return Result.success();
    }

    @PostMapping("/add")
    public Result add(@RequestBody FodderRecord fodderRecord){
        fodderService.add(fodderRecord);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody FodderRecord fodderRecord){
        fodderService.update(fodderRecord);
        return Result.success();
    }
}
